package cn.edu.scau.cmi.zhengweixin.abstractFactory;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;

public class FactoryController {

	@FXML
	private ResourceBundle resources;

	@FXML
	private URL location;

	@FXML
	private ChoiceBox<String> choiceBox;

	@FXML
	private ChoiceBox<String> companyChoiceBox;

	@FXML
	private Button outputButton;

	@FXML
	private TextArea outputTextArea;

	@FXML
	private ImageView photo;

	@FXML
	void output(ActionEvent event) {
		InsuranceFactory factory = null;
		switch (companyChoiceBox.getSelectionModel().getSelectedIndex()) {
		case 0: {
			factory = new PICCInsuranceFactory();
			break;
		}
		case 1: {
			factory = new PingAnInsuranceFactory();
			break;
		}
		default:
			outputTextArea.appendText("请选择保险公司\n");
			return;
		}
		
		Insurance insurance = null;
		switch (choiceBox.getSelectionModel().getSelectedIndex()) {
		case 0: {
			insurance = factory.createDriverInsurance();
			break;
		}
		case 1: {
			insurance = factory.createCarInsurance();
			break;
		}
		case 2: {
			insurance = factory.createPassengerInsurance();
			break;
		}
		case 3: {
			insurance = factory.createOtherInsurance();
			break;
		}
		default:
			outputTextArea.appendText("请选择保险类型\n");
			return;
		}
		
		outputTextArea.appendText("保险公司类型" + factory.getClass() + ", 保险服务内容:" + insurance.message() + "\n");

	}
	
	@FXML
	void selectCompany(MouseEvent event) {
		companyChoiceBox.setItems(FXCollections.observableArrayList("中国人寿保险", "平安保险"));
	}

	@FXML
	void selectType(MouseEvent event) {
		choiceBox.setItems(FXCollections.observableArrayList("司机受伤", "汽车损坏", "人员伤亡", "多种事故"));
	}

	@FXML
	void initialize() {
		assert choiceBox != null : "fx:id=\"choiceBox\" was not injected: check your FXML file 'Factory.fxml'.";
		assert outputButton != null : "fx:id=\"outputButton\" was not injected: check your FXML file 'Factory.fxml'.";
		assert outputTextArea != null : "fx:id=\"outputTextArea\" was not injected: check your FXML file 'Factory.fxml'.";
		assert photo != null : "fx:id=\"photo\" was not injected: check your FXML file 'Factory.fxml'.";
	}

}
